<?php
// +----------------------------------------------------------------------
// | Wap访问检查行为(woshimaijiapublish
// +----------------------------------------------------------------------
// | @link ( http://www.yurnero.net )
// +----------------------------------------------------------------------
// | @copyright
// +----------------------------------------------------------------------
// | @licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | @author Haijun Wu <nicholasinlove@126.com>
// +----------------------------------------------------------------------
// | $Id: WapCheckBehavior.class.php 104 2011-04-29 03:45:27Z nicholasinlove1986@gmail.com $
// +----------------------------------------------------------------------


class WapCheckBehavior extends Behavior {

	public function run() {
		$wapUrl = C('WAP_REDIRECT_URL') || '/Wap';
		if (C('WAP_REDIRECT_ON') && self::isWap()) {
			header('Location:' . $wapUrl);
			exit;
		}
	}
	
	static private function isWap() {
		$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
		$uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|sie|philips|panasonic|alcatel|lenovo|cldc|midp|wap|mobile)/i";
		if (($ua == '' || preg_match($uachar, $ua)) && !strpos(strtolower($_SERVER['REQUEST_URI']), 'wap')) {
			return true;
		} else {
			return false;
		}
	}
}

?>